//
//  GLMainViewController.m
//  QAQ打飞机
//
//  Created by admin on 15/8/28.
//  Copyright (c) 2015年 gl. All rights reserved.
//

#import "GLMainViewController.h"
#import "GLLoadingView.h"
#import "GLWelcome.h"
#import "GLGameViewController.h"
#import "GLSoundToo.h"
#import "GLImageResource.h"
#import "GLEnterView.h"
@interface GLMainViewController ()
{
   //加载时的动画视图
    GLLoadingView*_loadingView;
   //欢迎视图
    GLWelcome *_welcome;
   //加载游戏视图
    GLGameViewController *_gameView;
    GLSoundToo *_soundToo;
    //
   
  
    //图像数据
    GLImageResource *_imageresource;
    //声音
    GLSoundToo*_soundtoo;
   
}
@end

@implementation GLMainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor blackColor]];
    

    _soundToo =[[GLSoundToo alloc]init];
    
    //添加加载视图
    _loadingView =[[GLLoadingView alloc]initWithFrame:self.view.bounds];
    
    [self.view addSubview:_loadingView];
    //
    [self performSelectorInBackground:@selector(loadResourse) withObject:nil];
  
}
#pragma mark -私有方法
#pragma mark 加载资源的方法
-(void)loadResourse
{
    
   
    //1.加载资源
    //使用线程休眠方法
    [NSThread sleepForTimeInterval:4.0f];
    NSLog(@"加载中。。。");
    _gameView =[[GLGameViewController alloc]init];
    [_gameView loadResources];
    //2.删除启动动画
    [_loadingView removeFromSuperview];
    
    //3.加载欢迎视图
    _welcome =[[GLWelcome alloc]initWithFrame:self.view.bounds];
    [self.view addSubview:_welcome];
    
    //4.用后台程序进入游戏视图
    [self performSelectorInBackground:@selector(enterGame) withObject:nil];


}

#pragma make 进入游戏
-(void)enterGame
{
    //1.停顿一秒
    [NSThread sleepForTimeInterval:1.0];
    [_soundToo playAudioWithName:kVoice3];
    //2.删除欢迎视图
    [_welcome removeFromSuperview];

    //3.进入游戏视图
    [self.view addSubview:_gameView.view];

}


@end
